package io.renren.modules.erp.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.erp.entity.PaperTypeEntity;
import io.renren.modules.erp.service.PaperTypeService;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-07-19 22:30:09
 */
@RestController
@RequestMapping("erp/papertype")
public class PaperTypeController {
    @Autowired
    private PaperTypeService paperTypeService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("erp:papertype:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = paperTypeService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{paperTypeId}")
    @RequiresPermissions("erp:papertype:info")
    public R info(@PathVariable("paperTypeId") Long paperTypeId){
        PaperTypeEntity paperType = paperTypeService.selectById(paperTypeId);

        return R.ok().put("paperType", paperType);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("erp:papertype:save")
    public R save(@RequestBody PaperTypeEntity paperType){
        paperTypeService.insert(paperType);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("erp:papertype:update")
    public R update(@RequestBody PaperTypeEntity paperType){
        ValidatorUtils.validateEntity(paperType);
        paperTypeService.updateAllColumnById(paperType);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("erp:papertype:delete")
    public R delete(@RequestBody Long[] paperTypeIds){
        paperTypeService.deleteBatchIds(Arrays.asList(paperTypeIds));

        return R.ok();
    }

}
